package com.fitness.front.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fitness.front.modal.coach.entity.Coach;
import com.fitness.front.modal.coach.param.CoachPageQueryParams;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface CoachMapper extends BaseMapper<Coach> {

    @Select("<script>select * from t_coach c"
            + " <where>"
            + "<if test='queryParams.keyword != null and queryParams.keyword.trim() neq \"\"'>"
            + " AND c.real_name like  CONCAT('%',#{queryParams.keyword},'%')"
            + "</if>"
            + "</where>"
            +"</script>")
    Page<Coach> getCoachPage(Page<Coach> page, @Param("queryParams") CoachPageQueryParams queryParams);

    @Select("SELECT * FROM t_coach tc WHERE id NOT IN (SELECT coach_id FROM t_course_schedule tcs " +
            "WHERE status = 0 AND (start_time > #{endTime} OR end_time < #{startTime}))")
    List<Coach> queryAvailableCoach(@Param("startTime") String startTime,@Param("endTime") String endTime);
}
